﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsApplication1.DAL;
using System.Data;

namespace WindowsFormsApplication1.BLL
{
    class PersistanceUtility
    {
        DataAccess da;

        public PersistanceUtility()
        {
            da = new DataAccess();
        }

        public void AddPerson(Person newPerson)
        {
            da.AddPerson(newPerson.FirstName, newPerson.LastName, newPerson.Phone, newPerson.BrushColor);
        }

        public List<Person> GetPersonList()
        {
            List<Person> list = new List<Person>();
            DataTable results = new DataTable();
            results = da.GetPersonList();

            foreach (DataRow row in results.Rows)
            {
                Person newPerson = new Person();
                newPerson.Id = int.Parse(row["peopleID"].ToString());
                newPerson.FirstName = row["fName"].ToString();
                newPerson.LastName = row["lName"].ToString();
                newPerson.Phone = row["phone"].ToString();
                newPerson.BrushColor = row["BrushColor"].ToString();

                list.Add(newPerson);

            }

            return list;
        }
    }
}
